
// LotroLCDDoc.cpp : implementation of the CLotroLCDDoc class
//

#include "stdafx.h"
// SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail
// and search filter handlers and allows sharing of document code with that project.
#ifndef SHARED_HANDLERS
#include "LotroLCD.h"
#endif

#include "LotroLCDDoc.h"

#include <propkey.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// CLotroLCDDoc

IMPLEMENT_DYNCREATE(CLotroLCDDoc, CDocument)

BEGIN_MESSAGE_MAP(CLotroLCDDoc, CDocument)
END_MESSAGE_MAP()


// CLotroLCDDoc construction/destruction

CLotroLCDDoc::CLotroLCDDoc()
{
	// TODO: add one-time construction code here
	TRACE("CLotroLCDDoc::CLotroLCDDoc\n");
	// Return max screen resolution divided by two as default size
	//m_sizeDoc = CSize(GetSystemMetrics(SM_CXSCREEN)/2, GetSystemMetrics(SM_CYSCREEN)/2);
	m_sizeDoc = CSize(GetSystemMetrics(SM_CXSCREEN)/2, 600);

}

CLotroLCDDoc::~CLotroLCDDoc()
{
}

BOOL CLotroLCDDoc::OnNewDocument()
{
	TRACE("Entering  CLotroLCDDoc::OnNewDocument\n");
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)
	return TRUE;
}

// CLotroLCDDoc serialization

void CLotroLCDDoc::Serialize(CArchive& ar)
{
	TRACE("Entering CLotroLCDDoc::Serialize\n");
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO replace with realtime combat log, show readme for now
		//ar >> m_sizeDoc;
		char pb[100000];
		UINT read = ar.Read( pb, 100000 );
			if (read)
			{
				pb[read] = 0;
				readme = pb;
			}
			//Calculate text area for scrolling
			CRect rect;
			CDC dcTemp;
			dcTemp.CreateCompatibleDC(NULL);
			m_sizeDoc.cy = DrawText (dcTemp,readme, -1, rect, DT_CALCRECT | DT_LEFT | DT_TOP);
	}
}

#ifdef SHARED_HANDLERS

// Support for thumbnails
void CLotroLCDDoc::OnDrawThumbnail(CDC& dc, LPRECT lprcBounds)
{
	// Modify this code to draw the document's data
	dc.FillSolidRect(lprcBounds, RGB(255, 255, 255));

	CString strText = _T("TODO: implement thumbnail drawing here");
	LOGFONT lf;

	CFont* pDefaultGUIFont = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT));
	pDefaultGUIFont->GetLogFont(&lf);
	lf.lfHeight = 36;

	CFont fontDraw;
	fontDraw.CreateFontIndirect(&lf);

	CFont* pOldFont = dc.SelectObject(&fontDraw);
	dc.DrawText(strText, lprcBounds, DT_CENTER | DT_WORDBREAK);
	dc.SelectObject(pOldFont);
}

// Support for Search Handlers
void CLotroLCDDoc::InitializeSearchContent()
{
	CString strSearchContent;
	// Set search contents from document's data. 
	// The content parts should be separated by ";"

	// For example:  strSearchContent = _T("point;rectangle;circle;ole object;");
	SetSearchContent(strSearchContent);
}

void CLotroLCDDoc::SetSearchContent(const CString& value)
{
	if (value.IsEmpty())
	{
		RemoveChunk(PKEY_Search_Contents.fmtid, PKEY_Search_Contents.pid);
	}
	else
	{
		CMFCFilterChunkValueImpl *pChunk = NULL;
		ATLTRY(pChunk = new CMFCFilterChunkValueImpl);
		if (pChunk != NULL)
		{
			pChunk->SetTextValue(PKEY_Search_Contents, value, CHUNK_TEXT);
			SetChunkValue(pChunk);
		}
	}
}

#endif // SHARED_HANDLERS

// CLotroLCDDoc diagnostics

#ifdef _DEBUG
void CLotroLCDDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CLotroLCDDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG


// CLotroLCDDoc commands
